<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商品注册</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            font-family: Arial, sans-serif;
            background-color: #f5f5f5;
        }
        .register-container {
            width: 350px;
            padding: 20px;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }
        .register-container h2 {
            margin-bottom: 20px;
            text-align: center;
        }
        .form-group {
            margin-bottom: 15px;
        }
        .form-group label {
            display: block;
            margin-bottom: 5px;
            font-size: 14px;
            color: #333;
        }
        .form-group input, .form-group textarea, .form-group select {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 14px;
            margin-top: 5px;
            box-sizing: border-box;
        }
        .form-group input[type="file"] {
            padding: 3px;
        }
        .register-button {
            width: 100%;
            padding: 12px;
            background-color: #4CAF50;
            color: #fff;
            border: none;
            border-radius: 4px;
            font-size: 16px;
            cursor: pointer;
            margin-top: 20px;
        }
        .register-button:hover {
            background-color: #45a049;
        }
        .image-preview {
            display: block;
            margin-top: 10px;
            max-width: 100%;
            max-height: 200px;
            border: 1px solid #ddd;
            padding: 5px;
        }
    </style>
    <script>
        function previewImage(event) {
            const fileInput = event.target;
            const preview = document.getElementById("imagePreview");
            const file = fileInput.files[0];
            const reader = new FileReader();

            reader.onload = function(e) {
                preview.src = e.target.result;
                preview.style.display = "block";
            };

            if (file) {
                reader.readAsDataURL(file);
            }
        }
    </script>
</head>
<body>

<div class="register-container">
    <h2>商品注册</h2>
    <form action="./productRegServlet" method="POST" enctype="multipart/form-data">
        <div class="form-group">
            <label for="productName">商品名称</label>
            <input type="text" id="productName" name="productName" required>
        </div>

        <div class="form-group">
            <label for="price">价格</label>
            <input type="number" id="price" name="price" required min="0" step="0.01" placeholder="请输入商品价格">
        </div>

        <div class="form-group">
            <label for="star">单件积分</label>
            <input type="number" id="star" name="star" required min="0" step="0.01" placeholder="请输入商品单件积分">
        </div>

        <div class="form-group">
            <label for="description">商品描述</label>
            <textarea id="description" name="description" rows="4" required placeholder="请输入商品描述"></textarea>
        </div>

        <div class="form-group">
            <label for="image">商品图片</label>
            <input type="file" id="image" name="image" accept="image/*" required onchange="previewImage(event)">
            <img id="imagePreview" class="image-preview" style="display:none;" />
        </div>

        <button type="submit" class="register-button">注册商品</button>
    </form>
</div>

</body>
</html>
